package o;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
import javax.annotation.Nullable;
import javax.net.ssl.SSLSocket;

class fwt extends fwy {
    private final Method ˊ;
    private final Method ˋ;
    private final Class<?> ˎ;
    private final Class<?> ˏ;
    private final Method ॱ;

    static class c implements InvocationHandler {
        String ˊ;
        boolean ˋ;
        private final List<String> ˏ;

        c(List<String> list) {
            this.ˏ = list;
        }

        public Object invoke(Object obj, Method method, Object[] objArr) throws Throwable {
            String name = method.getName();
            Class returnType = method.getReturnType();
            if (objArr == null) {
                objArr = fvg.ˋ;
            }
            if (name.equals("supports") && Boolean.TYPE == returnType) {
                return Boolean.valueOf(true);
            }
            if (name.equals("unsupported") && Void.TYPE == returnType) {
                this.ˋ = true;
                return null;
            } else if (name.equals("protocols") && objArr.length == 0) {
                return this.ˏ;
            } else {
                if ((name.equals("selectProtocol") || name.equals("select")) && String.class == returnType && objArr.length == 1 && (objArr[0] instanceof List)) {
                    List list = (List) objArr[0];
                    int size = list.size();
                    for (int i = 0; i < size; i++) {
                        if (this.ˏ.contains(list.get(i))) {
                            name = (String) list.get(i);
                            this.ˊ = name;
                            return name;
                        }
                    }
                    name = (String) this.ˏ.get(0);
                    this.ˊ = name;
                    return name;
                } else if ((!name.equals("protocolSelected") && !name.equals("selected")) || objArr.length != 1) {
                    return method.invoke(this, objArr);
                } else {
                    this.ˊ = (String) objArr[0];
                    return null;
                }
            }
        }
    }

    fwt(Method method, Method method2, Method method3, Class<?> cls, Class<?> cls2) {
        this.ˋ = method;
        this.ˊ = method2;
        this.ॱ = method3;
        this.ˎ = cls;
        this.ˏ = cls2;
    }

    public void ॱ(SSLSocket sSLSocket, String str, List<fut> list) {
        Exception e;
        List ˎ = fwy.ˎ(list);
        try {
            Object newProxyInstance = Proxy.newProxyInstance(fwy.class.getClassLoader(), new Class[]{this.ˎ, this.ˏ}, new c(ˎ));
            this.ˋ.invoke(null, new Object[]{sSLSocket, newProxyInstance});
        } catch (InvocationTargetException e2) {
            e = e2;
            throw fvg.ॱ("unable to set alpn", e);
        } catch (IllegalAccessException e3) {
            e = e3;
            throw fvg.ॱ("unable to set alpn", e);
        }
    }

    public void ˏ(SSLSocket sSLSocket) {
        Exception e;
        try {
            this.ॱ.invoke(null, new Object[]{sSLSocket});
        } catch (IllegalAccessException e2) {
            e = e2;
            throw fvg.ॱ("unable to remove alpn", e);
        } catch (InvocationTargetException e3) {
            e = e3;
            throw fvg.ॱ("unable to remove alpn", e);
        }
    }

    @Nullable
    public String ˊ(SSLSocket sSLSocket) {
        Exception e;
        try {
            c cVar = (c) Proxy.getInvocationHandler(this.ˊ.invoke(null, new Object[]{sSLSocket}));
            if (cVar.ˋ || cVar.ˊ != null) {
                return cVar.ˋ ? null : cVar.ˊ;
            }
            fwy.ˋ().ˏ(4, "ALPN callback dropped: HTTP/2 is disabled. Is alpn-boot on the boot class path?", null);
            return null;
        } catch (InvocationTargetException e2) {
            e = e2;
            throw fvg.ॱ("unable to get selected protocol", e);
        } catch (IllegalAccessException e3) {
            e = e3;
            throw fvg.ॱ("unable to get selected protocol", e);
        }
    }

    public static fwy ˏ() {
        try {
            String str = "org.eclipse.jetty.alpn.ALPN";
            Class cls = Class.forName(str);
            Class cls2 = Class.forName(str + "$Provider");
            Class cls3 = Class.forName(str + "$ClientProvider");
            Class cls4 = Class.forName(str + "$ServerProvider");
            return new fwt(cls.getMethod("put", new Class[]{SSLSocket.class, cls2}), cls.getMethod("get", new Class[]{SSLSocket.class}), cls.getMethod("remove", new Class[]{SSLSocket.class}), cls3, cls4);
        } catch (ClassNotFoundException e) {
        } catch (NoSuchMethodException e2) {
        }
        return null;
    }
}
